/*
 * OREKIT-X
 * Copyright 2002-2008 CS Communication & Systemes
 * 
 * Parts of this software package have been licensed to CS
 * Communication & Systemes (CS) under one or more contributor license
 * agreements.  See the NOTICE file distributed with this work for
 * additional information.
 *  
 * This is an experimental copy of OREKIT from www.orekit.org.
 * Please use the original OREKIT from orekit.org for normal work
 * unrelated to this research project.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License.  You
 * may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package ore.time;

/** 
 * Offset between {@link UTCScale UTC} and {@link TAIScale TAI} time
 * scales.
 * 
 * The {@link UTCScale UTC} and {@link TAIScale TAI} time scales are
 * two scales offset with respect to each other. The {@link TAIScale
 * TAI} scale is continuous whether the {@link UTCScale UTC} includes
 * some discontinuity when leap seconds are introduced by the <a
 * href="http://www.iers.org/">International Earth Rotation
 * Service</a> (IERS).
 * 
 * This class represents the constant offset between the two scales
 * that is valid between two leap seconds occurrences.
 * 
 * @author Luc Maisonobe
 * 
 * @see UTCScale
 * @see UTCTAIHistoryFilesLoader
 */
public class UTCTAIOffset 
    extends Object
    implements TimeStamped, 
               java.io.Serializable
{
    /** 
     * Leap date.
     */
    public final AbsoluteDate leapDate;
    /** 
     * Offset start of validity date.
     */
    public final AbsoluteDate validityStart;
    /** 
     * Offset end of validity date.
     */
    private AbsoluteDate validityEnd;
    /** 
     * Value of the leap at offset validity start (in seconds).
     */
    public final double leap;
    /** 
     * Offset in seconds (TAI minus UTC).
     */
    public final double offset;

    /** 
     * @param leapDate Leap date
     * @param leap Value of the leap at offset validity start (in seconds)
     * @param offset Offset in seconds (TAI minus UTC)
     */
    public UTCTAIOffset(AbsoluteDate leapDate, double leap, double offset) {
        super();
        this.leapDate      = leapDate;
        this.validityStart = new AbsoluteDate(leapDate, leap);
        this.validityEnd   = AbsoluteDate.FUTURE_INFINITY;
        this.leap          = leap;
        this.offset        = offset;
    }


    /** 
     * @return Date of the start of the leap
     */
    public AbsoluteDate getDate() {
        return this.leapDate;
    }
    /** 
     * The start of the validity of the offset is {@link #getLeap()}
     * seconds after the start of the leap itsef.
     * 
     * @return Start of validity date for this offset
     */
    public AbsoluteDate getValidityStart() {
        return this.validityStart;
    }
    /** 
     * The end of the validity of the offset is the date of the start
     * of the leap leading to the next offset.
     * 
     * @return End of validity for this offset.
     */
    public AbsoluteDate getValidityEnd() {
        return this.validityEnd;
    }
    /** 
     * @param validityEnd End of validity 
     */
    protected void setValidityEnd(AbsoluteDate validityEnd) {
        this.validityEnd = validityEnd;
    }
    /** 
     * @return Value of the leap at offset validity start (in seconds)
     */
    public double getLeap() {
        return this.leap;
    }
    /** 
     * @return Offset in seconds.
     */
    public double getOffset() {
        return this.offset;
    }
    public final int compareTo(TimeStamped stamped){
        return this.getDate().compareTo(stamped);
    }
}
